package config

import (
	"github.com/Unknwon/goconfig"
	"gopkg.in/mgo.v2"
	"time"
)

//读取下配置文件
var Conf = map[string]interface{}{"app_env": "dev"}
var Session *mgo.Session
var App interface{}
var ControllerMap map[string]interface{} = map[string]interface{}{
}

func InitMongoLocalSession(){
	var config = Conf["config_sys"].(*goconfig.ConfigFile)
	var timeout = config.MustInt("mongo", "timeout", 5)
	dailInfo := &mgo.DialInfo{
		Addrs:[]string{config.MustValue("mongo", "uri", "127.0.0.1:27017")},
		Direct: false,
		Timeout: time.Second * time.Duration(timeout),
		Database: config.MustValue("mongo", "database", "supsite"),
		Source: config.MustValue("mongo", "source", "admin"),
		PoolLimit: config.MustInt("mongo", "pool", 100),
	}
	session, err := mgo.DialWithInfo(dailInfo)
	session.SetMode(mgo.Monotonic, true)
	if err != nil {
		panic(err.Error())
	}
	Session = session
}

func GetSession() *mgo.Session {
	return Session
}


